home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / Information / CSMP Digest / volume 1 / csmp-v1-200.txt < prev    next >
Encoding:
Text File  |  1994-12-08  |  45.9 KB  |  1,352 lines  |  [TEXT/R*ch]

  1. C.S.M.P. Digest             Sun, 01 Nov 92       Volume 1 : Issue 200
  2.  
  3. Today's Topics:
  4.  
  5.     fastQSort.p (Pascal port of  fastQsort.c)
  6.     SUMMARY: How to <<Readln>> from a handle? 
  7.     bugs in Think C 5.0.3 floating point routines?
  8.     Think C, Interrupts and restoring A5
  9.     Patching GetResource
  10.     How to detect movable modal WDEF?
  11.  
  12.  
  13.  
  14. The Comp.Sys.Mac.Programmer Digest is moderated by Michael A. Kelly.
  15.  
  16. The digest is a collection of article threads from the internet newsgroup
  17. comp.sys.mac.programmer.  It is designed for people who read c.s.m.p. semi-
  18. regularly and want an archive of the discussions.  If you don't know what a
  19. newsgroup is, you probably don't have access to it.  Ask your systems
  20. administrator(s) for details.  (This means you can't post questions to the
  21. digest.)
  22.  
  23. Each issue of the digest contains one or more sets of articles (called
  24. threads), with each set corresponding to a 'discussion' of a particular
  25. subject.  The articles are not edited; all articles included in this digest
  26. are in their original posted form (as received by our news server at
  27. cs.uoregon.edu).  Article threads are not added to the digest until the last
  28. article added to the thread is at least one month old (this is to ensure that
  29. the thread is dead before adding it to the digest).  Article threads that
  30. consist of only one message are generally not included in the digest.
  31.  
  32. The entire digest is available for anonymous ftp from ftp.cs.uoregon.edu
  33. [128.223.8.8] in the directory /pub/mac/csmp-digest.  Be sure to read the
  34. file /pub/mac/csmp-digest/README before downloading any files.  The most
  35. recent issues are available from sumex-aim.stanford.edu [36.44.0.6] in the
  36. directory /info-mac/digest/csmp.  If you don't have ftp capability, the sumex
  37. archive has a mail server; send a message with the text '$MACarch help' (no
  38. quotes) to LISTSERV@ricevm1.rice.edu for more information.
  39.  
  40. The digest is also available via email.  Just send a note saying that you
  41. want to be on the digest mailing list to mkelly@cs.uoregon.edu, and you will
  42. automatically receive each new issue as it is created.  Sorry, back issues
  43. are not available through the mailing list.
  44.  
  45. Send administrative mail to mkelly@cs.uoregon.edu.
  46.  
  47.  
  48. -------------------------------------------------------
  49.  
  50. From: mxmora@unix.sri.com (Matthew Xavier Mora)
  51. Subject: fastQSort.p (Pascal port of  fastQsort.c)
  52. Date: 28 Sep 92 22:58:59 GMT
  53. Organization: SRI International
  54.  
  55. I don't remember seeing this get posted so I'll post another copy.
  56. This is the Pascal version of Hadyn Huntley's fastQsort.c that was
  57. posted here long ago. Since I posted a request for sorting code in pascal,
  58. I thought I should post this for the net in case anyone else is 
  59. interested.
  60.  
  61. It could use a better memswap if someone has one.
  62.  
  63. Matt
  64.  
  65.  
  66.  
  67. {------------------------------------------------}
  68. { fastQsort port by Matthew Xavier Mora based on }
  69. { Hadyn Huntley fastqsort.c                      }
  70. { posted to C.S.M.P. on 09-28-92                 }
  71. {                                                }
  72. {Researched and written by:                      }
  73. {                                                }
  74. {        Haydn Huntley                                 }
  75. {        Haydn's Consulting                            }
  76. {        203 West Stone                                }
  77. {        Fairfield, Iowa  52556                        }
  78. {    (515) 472-7025                                 }
  79. {                                                }        
  80. {    During the school year, I may be reached at the}
  81. { following address:                             }
  82. {                                                }    
  83. {        Haydn Huntley                                 }
  84. {        Eigenmann Hall #289                           }
  85. {        Indiana University                            }
  86. {        Bloomington, IN  47406                        }
  87. {        (812) 857-8620                                }
  88. {                                                }
  89. {    E-mail:  huntley@copper.ucs.indiana.edu        }
  90. {------------------------------------------------}
  91. unit fastqsort;
  92.  
  93. interface
  94.  
  95.     procedure FastQSort (base: Ptr; numberofRecords: longint; sizeofRecord:
  96. longint);
  97.  
  98. implementation
  99.  
  100.  
  101.     procedure FastQSort (base: Ptr; numberofRecords: longint; sizeofRecord:
  102. longint);
  103.         var
  104.             gSize: longint;
  105.             tmp, LowerLimit, UpperLimit: ptr;
  106.  
  107.         procedure memSwap (p, q: ptr; qSize: longint);
  108.  
  109.         begin
  110.             BlockMove(p, tmp, qSize);
  111.             BlockMove(q, p, qSize);
  112.             BlockMove(tmp, q, qSize);
  113.         end;
  114.  
  115.         function GetSize (var n: longint; last, first: ptr): integer;
  116.         begin
  117.             n := (ord(last) - Ord(first)) div gsize;
  118.             GetSize := n;
  119.         end;
  120.  
  121.         function cmpFn (aPtr, bPtr: ptr): integer;
  122.         begin
  123.             cmpFn := IUMagString(ptr(ord(aPtr) + 1), ptr(ord(bPtr) + 1), gsize,
  124. gsize);
  125.         end;
  126.  
  127. { ------------- begin doFastQSort ------------------------ }
  128.         procedure doFastQSort (first, last: ptr);
  129.             var
  130.                 i, j: Ptr;
  131.                 n: longint;
  132.         begin
  133.     { first, last, i, and j are scaled by gSize in this function }
  134.  
  135.             while ((getsize(n, last, first)) > 1) do
  136.                 begin
  137.  
  138.             { use a random pivot }
  139.                     memSwap(ptr(ord(first) + (abs(random) mod n) * gSize), first, gSize);
  140.  
  141.                     i := first;
  142.                     j := last;
  143.  
  144.                     while (true) do
  145.                         begin
  146.                             i := Ptr(ord(i) + gSize);
  147.                             while (ord(i) < ord(last)) and (CmpFn(i, first) < 0) do
  148.                                 i := Ptr(ord(i) + gSize);
  149.  
  150.                             j := Ptr(ord(j) - gSize);
  151.                             while (ord(j) > ord(first)) and (CmpFn(j, first) > 0) do
  152.                                 j := Ptr(ord(j) - gSize);
  153.  
  154.                             if (ord(i) >= ord(j)) then
  155.                                 leave;
  156.  
  157.                             memSwap(i, j, gSize);
  158.                         end;
  159.  
  160.                     if (j = first) then
  161.                         begin
  162.                             first := ptr(ord(first) + gSize);
  163.                             cycle;
  164.                         end;
  165.  
  166.                     memSwap(first, j, gSize);
  167.                     if (ord(j) - ord(first)) < (ord(last) - (ord(j) + gSize)) then
  168.                         begin
  169.                             doFastQSort(first, j);
  170.                             first := ptr(ord(j) + gSize);
  171.             { equivalent to doFastQSort (j + gSize, last);        }
  172.             { to save stack space                                }
  173.                         end
  174.                     else
  175.                         begin
  176.                             doFastQSort(ptr(ord(j) + gSize), last);
  177.                             last := j;
  178.             { equivalent to doFastQSort (first, j);            }
  179.             { to save stack space                                }
  180.                         end;
  181.                 end;
  182.         end;
  183. { ------------- begin FastQsort ------------------------ }
  184.     begin
  185.     { setup the global variables used by fastQSort() }
  186.  
  187.         gSize := sizeofRecord;
  188.         randseed := TickCount;
  189.         tmp := NewPtr(gsize);                         {temp ptr for swapping}
  190.   if tmp <> nil then 
  191.     begin 
  192.          { the args for fastQSort () must be scaled by gSize }
  193.             doFastQSort(base, ptr(ord(base) + (numberofRecords) * gSize));
  194.             DisposePtr(tmp);
  195.    end;
  196.     end;
  197. end.
  198.  
  199. ---------------------------
  200.  
  201. From: czychi@bernina.ethz.ch (Gary Czychi)
  202. Subject: SUMMARY: How to <<Readln>> from a handle? 
  203. Organization: Swiss Federal Institute of Technology (ETH), Zurich, CH
  204. Date: Wed, 30 Sep 1992 20:09:39 GMT
  205.  
  206.  
  207.  
  208. Almost two weeks ago, I asked the net how this could be done:  Given a
  209. normal handle to a chunk of data and read line for line (until the next CR)
  210. from it.
  211.  
  212. So here it is. First, I've appended my posting, and then in alphabetical
  213. order, the edited postings/mails from John B. Matthews
  214. <jmatthews@desire.wright.edu>, Matthew Hall <mhall@occs.cs.oberlin.edu>,
  215. Peter N Lewis <peter@cujo.curtin.edu.au> and Stepan Riha
  216. <stepan@natinst.com> (in alphabetical order).
  217.  
  218. I use the solution in my extended class library for the THINK Pascal class
  219. library in a class called "CPrepareText".  It's for all kind of text
  220. preparations, conversions and validations.  If you want it, just drop me a
  221. mail.  I will also post it to the TCL-Talk archive at
  222. ftp.brown.edu:/pub/tcl.
  223.  
  224. - ----------------------   Summary   ---------------------------------------
  225.  
  226. I have been told that the Mac (in fact any computer) is very slow reading
  227. textual input from a file line by line.
  228.  
  229. And in my application, I have already read in the text of a file in one big
  230. chunk and pass the handle to the place where I process the data.
  231.  
  232. Now, is there any way for me, to read some of the lines in this handle? I
  233. only need about 10 lines from the top and separate it from the rest, which
  234. is being diplayed in a window as one big part.
  235.  
  236. I've tried to type coerce the handle to a str255 handle, but then I get a
  237. range error (of course).
  238.  
  239. If there is no obvious or easy solution, how could I access the data in my
  240. handle byte for byte and then put everything into a Str255 until the next
  241. CR is detected?
  242.  
  243. - --------------------
  244.  
  245. Date:  Wed, 16 Sep 1992
  246. From:  "John B. Matthews" <JMATTHEWS@DESIRE.WRIGHT.edu>
  247. Message-ID:  <01GOTZWHTMS2000CO4@DESIRE.WRIGHT.EDU>
  248. To:  czychi@bernina.ethz.ch
  249. Subject:  How to <<Readln>> from a text referenced by a handle??
  250.  
  251.  
  252. function ReadString(h: CharsHandle; var index: Integer): Str255;
  253. {Get characters from index to CR (or 255 characters) and
  254.  update index to point to start of next string}
  255.  
  256. var i, limit: Integer; s: Str255;
  257.  
  258. begin
  259.   limit:= min(GetHandleSize(Handle(h)), SizeOf(Chars));
  260.   i:= index;
  261.   while (h^^[i]<>chr(13)) and (i<limit) and ((i-index)<255) do
  262.     i:= i+1;
  263.   BlockMove(pointer(ord(h^)+index), pointer(ord(@s)+1), i-index);
  264.   s[0]:= chr(i-index);
  265.   index:= i+1;
  266.   ReadString:= s;
  267. end;
  268.  
  269. The types Chars and CharsHandle are defined in TextEdit. The function
  270. min should be easy although you may want to make limit a LongInt to avoid
  271. type casts. I haven't tested this; it may be fragile for extreme data
  272. (eg. empty handle or all empty lines)
  273.  
  274. John B. Matthews, jmatthews@desire.wright.edu, disclaimer:= myViews <> WSU
  275. "Whom the gods would destroy, they first invite to program in C"
  276.  
  277. - --------------------
  278.  
  279.  to:
  280.  IN%"JMATTHEWS@DESIRE.WRIGHT.edu"
  281.  Reply: How to <<Readln>> from a  handle?
  282.  
  283.  
  284. Thanks a lot for your reply. In your code you use the BlockMove function
  285. which I've already seen (in IM) but never used before.  What exactly does
  286. it do?  Does it really move the data or does it copy of the data?
  287.  
  288. If it moves the data, what happens to the original data?  Will it be reduced by
  289. the amount of data which was moved and the size of it adjusted afterwards? That
  290. would be cute.
  291.  
  292. - --------------------
  293.  
  294.     17-SEP-1992
  295. From:   IN%"JMATTHEWS@DESIRE.WRIGHT.EDU"  "John B. Matthews"
  296. Subj:   RE: How to <<Readln>> from a  handle?
  297.  
  298. BlockMove (srcPtr, destPtr: Ptr; byteCount: LongInt); copies byteCount
  299. bytes from srcPtr to dstPtr. It works even if the source and destination
  300. overlap, although they don't in my example.
  301.  
  302. The original data is undisturbed, unless the source and destination
  303. overlap. There is no adjustment of size: the pointers are just addresses in
  304. memory. In my example, srcPtr is index bytes into a relocatable block while
  305. dstPtr is the second byte of a string on the stack.
  306.  
  307. It would have been nice to just write @h^^[index] and @s[1], but the @
  308. operator won't work on elements of a packed array. It's OK to dereference
  309. h the way I did (without locking it) since BlockMove won't move memory.
  310.  
  311. - --------------------
  312.  
  313. From:  "John B. Matthews" <JMATTHEWS@DESIRE.WRIGHT.edu>
  314. To:  czychi@bernina.ethz.ch
  315. Subject:  How to <<Readln>> from a text referenced by a handle??
  316.  
  317. This works much better:-)
  318.  
  319. program ReadStr;
  320.   var
  321.     wRect: Rect;
  322.     err: OSErr;
  323.     fRefNum: Integer;
  324.     i, count: LongInt;
  325.     h: Handle;
  326.     s: Str255;
  327.  
  328.   procedure ReadString (h: Handle; var index: LongInt; var s: Str255);
  329.   {Copy characters from index to CR (up to 255) into s}
  330.   {and update index to point to start of next string}
  331.     var
  332.       i, limit: LongInt;
  333.   begin
  334.     limit := GetHandleSize(h);
  335.     i := index;
  336.     while (CharsHandle(h)^^[i] <> chr(13)) and
  337.           (i < limit) and ((i - index) < 255) do
  338.       i := i + 1;
  339.     BlockMove(pointer(ord(h^) + index), pointer(ord(@s) + 1), i - index);
  340.     s[0] := chr(i - index);
  341.     index := i + 1;
  342.   end;
  343.  
  344. begin
  345.   InitCursor;
  346.   wRect := ScreenBits.bounds;
  347.   InsetRect(wRect, 50, 50);
  348.   SetTextRect(wRect);
  349.   ShowText;
  350.   err := FSOpen('ReadStr.p', 0, fRefNum);
  351.   err := GetEOF(fRefNum, count);
  352.   h := NewHandleClear(count);
  353.   if h <> nil then
  354.     err := FSRead(fRefNum, count, h^);
  355.   err := FSCLose(fRefNum);
  356.   i := 0;
  357.   while i < count do
  358.     begin
  359.       ReadString(h, i, s);
  360.       WriteLn(s)
  361.     end
  362. end.
  363.  
  364. - --------------------
  365.  
  366.     21-SEP-1992
  367. From:   IN%"JMATTHEWS@DESIRE.WRIGHT.EDU"  "John B. Matthews"
  368. Subj:   RE: How to <<Readln>> from a  handle?
  369.  
  370.  
  371. I was examining the generated code from the HReadLn method and noticed
  372. a potential problem: I examine each byte of the source text with the
  373. expression CharsHandle(h)^^[i] <> chr(13).
  374.  
  375. The relevant instruction is MOVE.B $00(A0,D7.W),D0 (address register
  376. indirect with index and displacement). The index register is treated
  377. as a sign extended word by default. This has the advantage of
  378. working correctly on 68000 machines (no odd address generation), but
  379. I think it breaks if i exceeds 32767.
  380.  
  381. The alternative, pointer(ord(h^) + i)^ <> 13, would break with an odd
  382. address error on 68000 machines. (A similar expression in the first
  383. argument to BlockMove is safe since BlockMove does the right thing.)
  384.  
  385. Is text > 32767 important? I guess I'd at least note the limitation
  386. in the comments.
  387.  
  388. John
  389.  
  390. - --------------------
  391.  
  392.     15 Sep 92
  393. From: mhall@occs.cs.oberlin.edu (Matthew Hall)
  394. Subject: How to <<Readln>> from a text referenced by a handle??
  395.  
  396.  
  397. Hello -
  398.  
  399. There are a number of ways to do this - To start off, first lock your
  400. handle.
  401. Now, you can just scan.  How you would do this is to declare
  402.  
  403. Type CharList = ^CharArray;
  404.      CharArray = array[0..0] of char;
  405.  
  406. var TheCharList :  CharList;
  407.     FileData :   Handle;
  408.     FilePos  : LONGINT;
  409.     CharPos,NumLine  : integer;
  410.     TheStrs : array[1..MAXLINES] of Str255;
  411.     TempStr :  Str255;
  412.  
  413. {FilePos records how far you are into the data, NumLine records which
  414. line you are currently on, CharPos is how many characters you are into
  415. the current line, and TheStrs are the strings you are placing the
  416. lines into.  A charlist is for typecasting, to fool THINK into
  417. thinking you are dealing with a stream of characters rather than just
  418. a huge block of bytes(same thing really.  That's why some people like
  419. C, you don't have to fool the compiler).  You set the address of
  420. TheCharList to the Master Pointer for TheFileData, and you can read of
  421. the characters just like an array.  WARNING: This method wont work if
  422. you try to access characters further than 32767 into the file.  That's
  423. a little more complicated and THINK has some silly quirks}
  424.  
  425. begin
  426. HLock(FileData);
  427. TheCharList:=CharListPtr(FileData^);
  428. FilePos:=0
  429. NumLines:=0;
  430. repeat
  431.   NumLine:=NumLine+1;
  432.   Charpos:=1
  433.   While TheCharList[CharPos]<><cr> do
  434.     begin
  435.       TempStr[CharPos]:=TheCharList[CharPos];
  436. {Remember, Type Str255 = array[0..255] of char, where Str[0] is the
  437. length of the string}
  438.       CharPos:=CharPos+1;
  439.     end
  440.   TempStr[0]:=chr(charpos-1); {Set the length byte of the string}
  441.   TheStrs[NumLine]:=TempStr;
  442. until NumLine=MAXLINES;
  443.  
  444. This should work - I forgot how to check if a character is a <cr> tho' Of
  445. course this could be made faster - A First step would be to remove the
  446. TempStr and replace it with TheStrs[numline][charpos]. There are other
  447. methods, you could use BlockMove.  Find the locations of the <cr>'s and
  448. just blockmove chunks into your strings.  However you still have to scan
  449. for the <cr>'s, and that's the slowest part.  I don't think, though, that
  450. this method will be noticible even.  Unless you are reading many lines, or
  451. from many, many files. If you are saving the files yourself, you could save
  452. them in string format,and it would be much quicker to retrieve them, but no
  453. other application would make sense of them.
  454.  
  455. Like I say, this method should be quick enough unless your needs are
  456. extreme. at 10 Mhz, if this compiles to 100 instructions at 100 cycles per
  457. intruction ( a bad case) you still get 1000 characters per second. (If your
  458. using TP's debug option, it may be 1/20'th of that)  Which should be more
  459. than 10 lines/second.
  460.  
  461. - -hope this helps
  462. - -matt hall
  463.  
  464. - --------------------
  465.  
  466.     16 Sep 92
  467. From: peter@cujo.curtin.edu.au (Peter N Lewis)
  468. Subject: Re: How to <<Readln>> from a text referenced by a handle??
  469.  
  470.  
  471. {$R-}
  472. procedure ReadALine(h:handle; var s:str255);
  473. var
  474.   p:ptr;
  475.   size,len:longInt;
  476. begin
  477.   p:=h^;
  478.   size:=GetHandleSize(h);
  479.   len:=0;
  480.   while (size>0) & (p^ <> 13) do begin
  481.     p:=ptr(ord(p)+1);
  482.     size:=size-1;
  483.     len:=len+1;
  484.   end;
  485.   if len>255 then len:=255;
  486.   s[0]:=chr(len);
  487.   BlockMove(h^,@s[1],len);
  488.   if size>0 then begin
  489.     p:=ptr(ord(p)+1); { Skip over the <cr> }
  490.     size:=size-1;
  491.     BlockMove(p,h^,size);
  492.   end;
  493.   SetHandleSize(h,size);
  494. end;
  495.  
  496. I tested this code, it seems to work ok.  Note, if you were going to read
  497. lots of lines, you'd be better keeping an offset, and avoiding the block
  498. move all the time, but the above will work ok, and isn't *that* inefficent,
  499. it depends how many times you want to call ReadALine, if its 10 or 20, no
  500. problem, if its 10 or 20 thousand, then some rethinking would be
  501. necessary...
  502.    Peter.
  503.  
  504. Peter N Lewis, NCRPDA, Curtin University       peter@cujo.curtin.edu.au
  505. GPO Box U1987, Perth WA 6001, AUSTRALIA             FAX: +61 9 367 8141
  506.  
  507. - --------------------
  508.  
  509.     16 Sep 92
  510. From: gurhs@uniwa.uwa.edu.au (Rhys Hollow)
  511. Subject: Re: How to <<Readln>> from a text referenced by a handle??
  512.  
  513.  
  514. peter@cujo.curtin.edu.au (Peter N Lewis) gives a useful example of
  515. implementing a Readln with a handle-referenced block of text :
  516.  
  517. >{$R-}
  518.  
  519. ...
  520.  
  521. Hmm, don't forget to turn Range Checking back on Pete!
  522.  
  523. Rhys.
  524.  
  525. Rhys Hollow (gurhs@uniwa.uwa.oz.au) "ee'er by gum he's a bad'un!" -DangerMouse.
  526.  
  527. - --------------------
  528.  
  529.     17-SEP-1992
  530. From:   IN%"peter@cujo.curtin.edu.au"  "Peter N Lewis"
  531. Subj:   RE: How to <<Readln>> from a  handle?
  532.  
  533.  
  534. > Does it really move the data or does it copy of the data?
  535.  
  536. No, it copies the data.  It will work correctly even if the source range
  537. and destination range overlap.
  538.  
  539. >If it moves the data, what happens to the original data?  Will it be reduced by
  540. >the amount of data which was moved and the size of it adjusted afterwards? That
  541. >would be cute.
  542.  
  543. No, but there is a procedure callen Munger, documented in IM1, which is
  544. totally cryptic, and which could have been used to do a bit of it, but
  545. figuring out munger is a pain.
  546.  
  547. BlockMove simply copies the block of memory, the original area is untouched
  548. (unless the destination and source areas overlap).
  549.  
  550. - --------------------
  551.  
  552.     Tue, Sep 15, 1992
  553. From: stepan@falcon.natinst.com (Stepan Riha)
  554. Subject:  How to <<Readln>> from a text referenced by a handle??
  555.  
  556.  
  557. Gary, I haven't worked with Pascal in a while but you should be able to
  558. dereference the handle and assign the value to a Pointer to a Character.
  559. Then you could dereference the pointer and call the successor function on
  560. it.
  561.  
  562. Procedure Foo(Handle h, integer len, var Str255 str);
  563. Const
  564.         CR = #13;       (* or however you declare a NewLine in Pascal *)
  565. Var
  566.         cPtr : Pointer TO Char;
  567.         i : Integer;
  568.         str : Str255;
  569. Begin
  570.         cPtr := h^;
  571.         i := 1;
  572.         while i<=len AND i<=255 AND cPtr^ <> CR do
  573.                 begin
  574.                         str[i] = cPtr^;
  575.                         cPtr := Succ(cPtr);
  576.                         i := Succ(i);
  577.                 end;
  578.         str[0] := i-1;
  579. end;
  580.  
  581. I'm not too sure about my syntax but this should do it.
  582.  
  583.         - Stepan
  584.  
  585. Stepan Riha -- stepan@natinst.com
  586.  
  587. - --------------------
  588. - --------------------
  589.  
  590. Thanks a lot to all who responded!
  591.  
  592.  
  593.   Gary
  594.  
  595.     Gary T. Czychi          University of St.Gallen
  596.  
  597.        czychi@alpha.unisg.ch (preferred host)
  598.          czychi at csghsg52   (=bitnet)
  599.            czychi@bernina.ethz.ch
  600.              Switzerland
  601.               -
  602.  
  603.  
  604.  
  605.  
  606. ---------------------------
  607.  
  608. From: ccssrg@gdr.bath.ac.uk (Simon Gray)
  609. Subject: bugs in Think C 5.0.3 floating point routines?
  610. Date: 23 Sep 92 11:18:54 GMT
  611. Organization: Bath University Computing Services, UK
  612.  
  613. Dear Netters
  614.  
  615. I have come across a  not so amusing problem with Think C 5.0.3
  616. running on a mac IIci with 8Mb RAM, system 7.0.1 and tuneup 1.1.1.
  617.  
  618. If I recompile the ANSI library with 4-byte ints turned on, the following
  619. code fails with a bomb:
  620.  
  621. #include<stdio.h>
  622. #include<stdlib.h>
  623.  
  624. main()
  625. {
  626. char a[20];
  627. scanf("%s", a);
  628. printf("%lf\n", atof(a));
  629. }
  630.  
  631.   :and by debugging the ANSI library source files, it crash appears to occur
  632. on calls to the function fp68k(). By adding short casts, indicated by
  633. my comments in the code below, the  above code will run successfully.
  634.  
  635. - ---- code segment extracted from scanf.c ANSI library sources folder ---
  636.  
  637. fp68k(&excp, (short)FPROCENTRY); /* ccssrg - added short cast */
  638.     if (d->sig[0]) {
  639.         fp68k(d, p, (short) (FOD2B + code));
  640.         fp68k(&excp, (short)FGETENV); /* ccssrg - added short cast */
  641.         fp68k(p, &kind, (short) (FOCLASS + code));
  642.         if (kind < 0)
  643.             kind = -kind;
  644.         if (kind == FCINF || (excp & (OVERFLOW<<8)))
  645.             c = 'I';
  646.         else if (kind == FCNORM && !(excp & (UNDERFLOW<<8)))
  647.             goto done;
  648.         errno = ERANGE;
  649.     }
  650. - ------------------ end segment ----------------
  651.  
  652. Unfortunately, it has become obvious that this is not the complete answer
  653. because a larger project that some colleagues are working on does not
  654. run successfully, using calls to fp68k(), even with the short casts added.
  655.  
  656. I have spoken to U.K. Symantec Tech Support (based in Holland!) and they
  657. have been 1) somewhat unhelpful
  658.           2) surprised at the bug
  659.           3) unable to suggest any solutions
  660.  
  661. Has any one out in netland had any similar experiences with these floating 
  662. point functions and have you found any other or better solutions?
  663.  
  664. If people would like to email their comments or thoughts to me, I will 
  665. summarise to the net.
  666.  
  667.  
  668. Simon Gray
  669. Small Systems Team
  670. Bath University Computing Services
  671. - ------------------------
  672. email: ccssrg@uk.ac.bath
  673. - ------------------------
  674.  
  675. +++++++++++++++++++++++++++
  676.  
  677. From: tonyg@cs.uq.oz.au (Tony Gedge)
  678. Date: 23 Sep 92 13:55:07 GMT
  679.  
  680. In <1992Sep23.111854.18781@gdr.bath.ac.uk> ccssrg@gdr.bath.ac.uk (Simon Gray) writes:
  681. >I have come across a  not so amusing problem with Think C 5.0.3
  682. >running on a mac IIci with 8Mb RAM, system 7.0.1 and tuneup 1.1.1.
  683.  
  684. The problem you mention has been in THINK C 5.0, 5.0.1 and 5.0.2.  I ran into
  685. it trying to port GhostScript to the mac.  In my case, the program *ran* more
  686. or less OK, however when you exited the compiler, the machine would shut down :(
  687.  
  688. >If I recompile the ANSI library with 4-byte ints turned on, the following
  689. >code fails with a bomb:
  690.  
  691. [source code deleted]
  692.  
  693. >  :and by debugging the ANSI library source files, it crash appears to occur
  694. >on calls to the function fp68k(). By adding short casts, indicated by
  695. >my comments in the code below, the  above code will run successfully.
  696.  
  697. [code segment deleted]
  698.  
  699. >Unfortunately, it has become obvious that this is not the complete answer
  700. >because a larger project that some colleagues are working on does not
  701. >run successfully, using calls to fp68k(), even with the short casts added.
  702.  
  703. This problem occurs in math.c printf.c and scanf.c (as I'm sure you
  704. are now aware! :-)  Did you get the two other related calls which have the
  705. same problem? [elems68k() and decstr68k()].
  706.  
  707. I think it occurrs because of the way in which the functions fp68k(),
  708. decstr() and elems68k() are declared.  If I remember correctly, the compiler
  709. ``promotes'' constants to a ``int'' if it doesn't have any prototype or cast
  710. to tell it otherwise.
  711.  
  712. >I have spoken to U.K. Symantec Tech Support (based in Holland!) and they
  713. >have been 1) somewhat unhelpful
  714. >          2) surprised at the bug
  715. >          3) unable to suggest any solutions
  716.  
  717. Doesn't surprise me if this bug has got through 3 patch levels so far :)
  718. Mind you, if everyone was like me and never bothered to tell them then maybe
  719. its a little understandable :) -- although it would appear that nobody
  720. properly tested the stdio library under 4-bit int mode..
  721.  
  722. >Has any one out in netland had any similar experiences with these floating 
  723. >point functions and have you found any other or better solutions?
  724.  
  725. The only thing I can suggest is to make sure you get all fp68k calls *and*
  726. elems68k() calls (I think there is one of those somewhere embedded in a macro)
  727. Since I ``fixed'' this a year or so back I can't remember exactly what changes
  728. I made, and you might have hit some other problem with the stdio library.
  729.  
  730. >If people would like to email their comments or thoughts to me, I will 
  731. >summarise to the net.
  732.  
  733. Have you been burnt by this one in console.c?
  734.     InitGraf(NewPtr(206) + 202);
  735. This line means (amoungst other things) that you can't use offscreen bitmaps
  736. and the console at the same time, because the Quickdraw globals won't be set
  737. up in the correct spot.  Took me ages to work out why the Quickdraw globals
  738. were all stupid in my software!
  739.  
  740. Good luck with your product,
  741.  
  742. Tony Gedge.
  743.  
  744. - --
  745. | Computer Science Department,       |  tonyg@cs.uq.oz.au   (Tony Gedge)  |
  746. | University of Queensland,          |  --------------------------------  |
  747. | Australia.                         |  "cc stands for Cryptic Crossword" |
  748. | FAX: +61 7 365 1999.               |  PH : +61 7 365 2445               |
  749.  
  750. +++++++++++++++++++++++++++
  751.  
  752. From: phils@chaos.cs.brandeis.edu (Phil Shapiro)
  753. Date: 24 Sep 92 14:34:05 GMT
  754. Organization: Symantec Corp.
  755.  
  756. OK, I guess it's time to run to THINK C's rescue.. :)
  757.  
  758. >>>>> On 23 Sep 92 13:55:07 GMT, tonyg@cs.uq.oz.au (Tony Gedge) said:
  759.  
  760.  > In <1992Sep23.111854.18781@gdr.bath.ac.uk> ccssrg@gdr.bath.ac.uk (Simon Gray) writes:
  761.  
  762. >>If I recompile the ANSI library with 4-byte ints turned on, the
  763. >>following code fails with a bomb:
  764.  
  765.  > [source code deleted]
  766.  
  767. >>  :and by debugging the ANSI library source files, it crash appears
  768. >>to occur on calls to the function fp68k(). By adding short casts,
  769. >>indicated by my comments in the code below, the above code will run
  770. >>successfully.
  771.  
  772.  > [code segment deleted]
  773.  
  774. >>Unfortunately, it has become obvious that this is not the complete
  775. >>answer because a larger project that some colleagues are working on
  776. >>does not run successfully, using calls to fp68k(), even with the
  777. >>short casts added.
  778.  
  779.  > This problem occurs in math.c printf.c and scanf.c (as I'm sure you
  780.  > are now aware! :-) Did you get the two other related calls which
  781.  > have the same problem? [elems68k() and decstr68k()].
  782.  
  783.  > I think it occurrs because of the way in which the functions
  784.  > fp68k(), decstr() and elems68k() are declared.  If I remember
  785.  > correctly, the compiler ``promotes'' constants to a ``int'' if it
  786.  > doesn't have any prototype or cast to tell it otherwise.
  787.  
  788. I'll bet money that you didn't just turn on the "4 byte ints" option,
  789. you also turned on the "enums are always ints" option as well. If
  790. that's the case, then the "enums are always ints" option is the source
  791. of your problems. The SANE header file (and possibly other toolbox
  792. headers as well) will not compile correctly with that option on, as
  793. you've seen. Since you're just recompiling ANSI, you can get by with
  794. just using "4 byte ints" only.
  795.  
  796. There are a couple reason why SANE.h is "broken" in this way, a
  797. summary is: (1) we wanted to use the MPW C headers with the mininum of
  798. change, (2) we wanted to support full ANSI C, including int sized
  799. enums, and (3) MPW C has no "enums are always ints" option, so it
  800. isn't an issue for MPW C users. I would agree that this should be
  801. covered in the User Manual or in the ReadMe file.
  802.  
  803.  > Have you been burnt by this one in console.c?
  804.  
  805.  >     InitGraf(NewPtr(206) + 202);
  806.  
  807.  > This line means (amoungst other things) that you can't use
  808.  > offscreen bitmaps and the console at the same time, because the
  809.  > Quickdraw globals won't be set up in the correct spot.  Took me
  810.  > ages to work out why the Quickdraw globals were all stupid in my
  811.  > software!
  812.  
  813. Well, there was a warning about exactly that in the C 4.0 Standard Lib
  814. Ref, I have no idea why it was removed from the 5.0 doc :-(. I'll make
  815. sure it gets added back in the next release.
  816.  
  817.     -phil
  818. - --
  819.    Phil Shapiro                                   Software Engineer
  820.    Language Products Group                     Symantec Corporation
  821.            Internet: phils@cs.brandeis.edu
  822.  
  823. ---------------------------
  824.  
  825. From: tree@kira.uvm.edu (Tom Emerson)
  826. Subject: Think C, Interrupts and restoring A5
  827. Date: 23 Sep 92 13:04:32 GMT
  828. Organization: University of Vermont, EMBA Computer Facility
  829.  
  830. In article <ejohnson.717224121@void> ejohnson@void.ncsa.uiuc.edu (Eric E. Johnson) writes:
  831.  
  832.    I suspect that my a5 is incorrect, and that this is the source of the
  833.    problem.  So, I pulled out Inside Macintosh, and checked to see how to
  834.    set and restore A5 for my application.  IM says they are SetUpA5 and
  835.    RestoreA5, however, Think C only had one that corresponded to SetUpA5.
  836.  
  837. According to IM-VI, p. 28-13, SetupA5/RestoreA5 cause problems with some
  838. optimizing compilers, and as such Apple has defined two new procedures,
  839. SetCurrentA5 and SetA5. These are defined in IM-VI pp.28-13--16 and M.ME.4-25.
  840.  
  841.    What did Think C rename RestoreA5 to?  I checked the Apple includes
  842.    that came with Think C, but no luck.  I checked the manual, but there
  843.    was only a discussion of setting and restoring A4.  Does Think C use
  844.    A4 instead of A5?
  845.  
  846. SetCurrentA5 and SetA5 are defined in OSUtils.h. THC provides a mechanism to
  847. address your global data off A4 rather than A5. We recommend this method over
  848. playing games with A5, though that is totally up to you.
  849.  
  850. Tom
  851. - --
  852.    Tom Emerson                                    Technical Support
  853.    Language Products Group                     Symantec Corporation
  854.             Internet: tree@uvm.edu
  855.  
  856. +++++++++++++++++++++++++++
  857.  
  858. From: ejohnson@void.ncsa.uiuc.edu (Eric E. Johnson)
  859. Date: 24 Sep 92 17:50:10 GMT
  860. Organization: University of Illinois at Urbana
  861.  
  862. >   I suspect that my a5 is incorrect, and that this is the source of the
  863. >   problem.  So, I pulled out Inside Macintosh, and checked to see how to
  864. >   set and restore A5 for my application.  IM says they are SetUpA5 and
  865. >   RestoreA5, however, Think C only had one that corresponded to SetUpA5.
  866.  
  867. >According to IM-VI, p. 28-13, SetupA5/RestoreA5 cause problems with some
  868. >optimizing compilers, and as such Apple has defined two new procedures,
  869. >SetCurrentA5 and SetA5. These are defined in IM-VI pp.28-13--16 and M.ME.4-25.
  870.  
  871. Here's the next question.  The code in IM-VI, on page 28-15,
  872. demonstrates how to get the application's A5 global variable by
  873. copying it out of the notification manager's field nmRefCon.  Fine, I
  874. understand how to set that up, but what if I'm using something like
  875. MacTCP's call back routine where the TCPNotify routine, which runs at
  876. interrupt time, has no way of knowing what the application's A5 global
  877. was to begin with.
  878.  
  879. >SetCurrentA5 and SetA5 are defined in OSUtils.h. THC provides a mechanism to
  880. >address your global data off A4 rather than A5. We recommend this method over
  881. >playing games with A5, though that is totally up to you.
  882.  
  883. What's the advatange of using A4 over A5?
  884.  
  885. Eric
  886.  
  887. +++++++++++++++++++++++++++
  888.  
  889. From: tree@kira.uvm.edu (Tom Emerson)
  890. Date: 24 Sep 92 21:55:50 GMT
  891. Organization: University of Vermont, EMBA Computer Facility
  892.  
  893. Eric Johnson writes:
  894.  
  895. [previous message excerpts deleted]
  896.  
  897. > Here's the next question.  The code in IM-VI, on page 28-15,
  898. > demonstrates how to get the application's A5 global variable by
  899. > copying it out of the notification manager's field nmRefCon.  Fine, I
  900. > understand how to set that up, but what if I'm using something like
  901. > MacTCP's call back routine where the TCPNotify routine, which runs at
  902. > interrupt time, has no way of knowing what the application's A5 global
  903. > was to begin with.
  904.  
  905. This type of situation is also discussed in IM-VI, p. 23-18. I'm not 
  906. familiar with the call back routines in MacTCP, but in effect you create 
  907. a new data structure that contains as its first element the information 
  908. the call back routine expects, and add to this a long to hold the value 
  909. of A5. Then you just put some assembly glue in your function to grab the 
  910. stored value of A5.
  911.  
  912. > What's the advatange of using A4 over A5?
  913.  
  914. By using the THINK A4 routines to handle globals in interrupts and such 
  915. things you completely avoid the need to store off A5 someplace where your 
  916. routine can find it. The dirty work is done for you.
  917.  
  918. Tom
  919. - --
  920.    Tom Emerson                                    Technical Support
  921.    Language Products Group                     Symantec Corporation
  922.             Internet: tree@uvm.edu
  923.  
  924. ---------------------------
  925.  
  926. From: davep@county.lmt.mn.org (Dave Polaschek)
  927. Subject: Patching GetResource
  928. Date: 22 Sep 92 15:01:34 GMT
  929. Organization: LaserMaster Corp
  930.  
  931. In article <keith-200992161425@kip-58.taligent.com> keith@taligent.com (Keith 
  932. Rollin) writes: 
  933. > I patch GetResource for globally replacing system resources. Once the
  934. > system has a handle to your resource, LoadResource will continue to get
  935. > your resource.
  936.  
  937. Keith (and any other wizards who might care to comment),
  938.  
  939. Doesn't this put quite a bit of extra overhead into every GetResource call?  
  940. I've considered using this type of patch to detect other applications loading 
  941. resources, and decided against doing so because of the added overhead (and I 
  942. only wanted to make the patch while my application was running).  It would 
  943. seem to me that this could have a pretty big impact on system performance in 
  944. general.
  945.  
  946. If the performance hit of this is going to be fairly minimal, I might 
  947. consider using it, but it still seems to me that this is going to slow down 
  948. an just about everything a user is going to do on a mac.  To be honest, I'm 
  949. not sure if there is another way to detect something like changing the MBDF 
  950. (or in my case noticing when the PAPA resource in the LaserWriter driver is 
  951. touched, so I can detect QuicKeys' Choosy extension), but I continue to 
  952. search for a better solution.
  953.  
  954. Just my two cents worth.
  955.  
  956. - -Dave
  957.  
  958. > In the following snippet:
  959. > o "gMyRefNum" is the resource refNum for my INIT, which holds my MBDF
  960. > o My INIT opens itself on the first call to InitAllPacks, and reshuffles
  961. > the
  962. >   resource chain so that it appears behind the System File.
  963. > o MyGetResource saves extra registers because of the comment on page I-113
  964. >   of IM.
  965. > o "oldGetResource" is a global variable holding the address returned by
  966. >   GetToolTrapAddress when I patched GetResource.
  967. > o I used THINK C, allowing me the use of A4 globals and inline assembly.
  968. > static pascal Handle    MyGetResource(ResType resType, short resID)
  969. > {
  970. >     short    oldResFile, newResFile;
  971. >     Handle    result;
  972. >     
  973. >     asm {
  974. >         movem.l    a1-a3/d1-d7,-(sp)
  975. >     }
  976. >     SetUpA4();
  977. >     
  978. >     newResFile = oldResFile = -1;
  979. >     if (gMyRefNum != 0) {
  980. >         //
  981. >         // If anyone ever asks for the standard MBDF, give them ours.
  982. >         //
  983. >         if (resType == 'MBDF' && resID == 0) {
  984. >             newResFile = gMyRefNum;
  985. >             resID = 1000;
  986. >         }
  987. >     }
  988. >     
  989. >     if (newResFile != -1) {
  990. >         oldResFile = CurResFile();
  991. >         UseResFile(newResFile);
  992. >     }
  993. >     result = oldGetResource(resType, resID);
  994. >     if (oldResFile != -1)
  995. >         UseResFile(oldResFile);
  996. >     RestoreA4();
  997. >     asm {
  998. >         movem.l (sp)+,a1-a3/d1-d7
  999. >     }
  1000. >     
  1001. >     return result;
  1002. > }
  1003. > -----
  1004. > Keith Rollin
  1005. > Phantom Programmer
  1006. > Taligent, Inc.
  1007.  
  1008. Dave Polaschek            Internet:davep@county.lmt.mn.org
  1009. LaserMaster Corp. R&D              ICBMNet:44^59'N 93^13'W
  1010. 7156 Shady Oak Road                     AppleLink:LASERMAX
  1011. Eden Prairie, MN 55344                   ATTNet:6129439204
  1012.  
  1013. +++++++++++++++++++++++++++
  1014.  
  1015. From: keith@taligent.com (Keith Rollin)
  1016. Date: 23 Sep 92 20:14:02 GMT
  1017. Organization: Taligent
  1018.  
  1019. In article <1992Sep22.150134.1512@lmt.mn.org>, davep@county.lmt.mn.org
  1020. (Dave Polaschek) wrote:
  1021. > In article <keith-200992161425@kip-58.taligent.com> keith@taligent.com (Keith 
  1022. > Rollin) writes: 
  1023. > > I patch GetResource for globally replacing system resources. Once the
  1024. > > system has a handle to your resource, LoadResource will continue to get
  1025. > > your resource.
  1026. > > 
  1027. > Keith (and any other wizards who might care to comment),
  1028. > Doesn't this put quite a bit of extra overhead into every GetResource call?  
  1029. > I've considered using this type of patch to detect other applications loading 
  1030. > resources, and decided against doing so because of the added overhead (and I 
  1031. > only wanted to make the patch while my application was running).  It would 
  1032. > seem to me that this could have a pretty big impact on system performance in 
  1033. > general.
  1034. > If the performance hit of this is going to be fairly minimal, I might 
  1035. > consider using it, but it still seems to me that this is going to slow down 
  1036. > an just about everything a user is going to do on a mac.  To be honest, I'm 
  1037. > not sure if there is another way to detect something like changing the MBDF 
  1038. > (or in my case noticing when the PAPA resource in the LaserWriter driver is 
  1039. > touched, so I can detect QuicKeys' Choosy extension), but I continue to 
  1040. > search for a better solution.
  1041.  
  1042. Well, take a look at what's going on in the patch, compared to what
  1043. GetResource does. Before the chained call to GetResource:
  1044.  
  1045.     asm {movem.l    a1-a3/d1-d7,-(sp)}
  1046.     SetUpA4();
  1047.     newResFile = oldResFile = -1;
  1048.  
  1049.     if (gMyRefNum != 0) {
  1050.         if (resType == 'MBDF' && resID == 0) {
  1051.             newResFile = gMyRefNum;
  1052.             resID = 1000;
  1053.         }
  1054.     }
  1055.     if (newResFile != -1) {
  1056.         oldResFile = CurResFile();
  1057.         UseResFile(newResFile);
  1058.     }
  1059.  
  1060. This stuff will execute in just about nothing flat. The only thing you
  1061. could point to are the calls to CurResFile() and UseResFile(). Neither of
  1062. these is a heavy-weight routine, and so shouldn't add much overhead.
  1063. Besides, they only get executed IF the system is asking for MBDF(0).
  1064.  
  1065. Following the chained call to GetResource:
  1066.  
  1067.     if (oldResFile != -1)
  1068.         UseResFile(oldResFile);
  1069.     RestoreA4();
  1070.     asm { movem.l (sp)+,a1-a3/d1-d7 }
  1071.     return result;
  1072.  
  1073. Again, none of this will take much time. The call to UseResFile will only
  1074. get called if we changed the current resfile above, which only happens if
  1075. the system is asking for MBDF(0). On a normal GetResource call, the
  1076. following happens:
  1077.  
  1078. - - Save registers
  1079. - - Setup A4
  1080. - - Set two locals to -1
  1081. - - Check gMyRefNum
  1082. - - Check resType (will almost always return FALSE)
  1083. - - Check newResFile (will almost always return FALSE)
  1084. * Call the original GetResource (chug, chug, chug)
  1085. - - Check OldResFile (will alsmost always return FALSE)
  1086. - - Restore A4
  1087. - - Restore registers
  1088. - - return result
  1089.  
  1090. None of the items marked with "-" will add appreciable overhead to the
  1091. actual heart of the GetResource call.
  1092.  
  1093. - -----
  1094. Keith Rollin
  1095. Phantom Programmer
  1096. Taligent, Inc.
  1097.  
  1098. ---------------------------
  1099.  
  1100. From: sw@network-analysis-ltd.co.uk (Sak Wathanasin)
  1101. Subject: How to detect movable modal WDEF?
  1102. Date: 23 Sep 92 14:19:21 GMT
  1103. Organization: Network Analysis Ltd
  1104.  
  1105. I'm working on an appl that needs to run in both sys 6 & 7. I would like to
  1106. use the movable modal for my dialogues, but fall back to plain old modal in
  1107. sys 6. How can I tell if the movable modal WDEF is available? I can't see
  1108. any Gestalt calls that will help... Thanks in advance for any ideas.
  1109.  
  1110.  
  1111. Sak Wathanasin
  1112. Network Analysis Limited
  1113. 178 Wainbody Ave South, Coventry CV3 6BX, UK
  1114.  
  1115. uucp:      ...!uknet!nan!sw  Phone: (+44) 203 419996
  1116. AppleLink: NAN.LTD           Internet: sw@network-analysis-ltd.co.uk
  1117.  
  1118. +++++++++++++++++++++++++++
  1119.  
  1120. From: smoke@well.sf.ca.us (Nicholas Jackiw)
  1121. Date: 23 Sep 92 16:59:16 GMT
  1122. Organization: Whole Earth 'Lectronic Link
  1123.  
  1124. In article <D2150050.ecero8@nan.network-analysis-ltd.co.uk> sw@network-analysis-ltd.co.uk writes:
  1125. >I'm working on an appl that needs to run in both sys 6 & 7. I would like to
  1126. >use the movable modal for my dialogues, but fall back to plain old modal in
  1127. >sys 6. How can I tell if the movable modal WDEF is available? I can't see
  1128. >any Gestalt calls that will help... Thanks in advance for any ideas.
  1129. >
  1130. >Sak Wathanasin
  1131.  
  1132. At the time Movable-Modal was released, one was encouraged to grab a
  1133. copy of it with ResEdit and stick it into your application's resource
  1134. fork.  Of course, this limits you to the functionality and bug-proofery
  1135. of a specific copy, but you can be fairly sure Apple won't be releasing
  1136. further upgrades of a 6.0 WDEF. (I haven't tried running the 7.0 WDEF
  1137. under 6.0.)  
  1138.  
  1139. Maybe Jim Reekes, who's on the net, could comment.  He wrote it, I believe.
  1140.  
  1141.  
  1142.  
  1143.  
  1144. - -- 
  1145.                               --- * ---
  1146. Nick Jackiw                  Smoke@well.sf.ca.us   | Jackiw@cs.swarthmore.edu
  1147. Key Curriculum Press, Inc.   Applelink:KEY.EDUSOFT | (510) 548-2304
  1148.                               --- * ---
  1149.  
  1150. +++++++++++++++++++++++++++
  1151.  
  1152. From: jcav@quads.uchicago.edu (JohnC)
  1153. Date: 23 Sep 92 18:26:34 GMT
  1154. Organization: The Royal Society for Putting Things on Top of Other Things
  1155.  
  1156. In article <D2150050.ecero8@nan.network-analysis-ltd.co.uk> sw@network-analysis-ltd.co.uk writes:
  1157. >I'm working on an appl that needs to run in both sys 6 & 7. I would like to
  1158. >use the movable modal for my dialogues, but fall back to plain old modal in
  1159. >sys 6. How can I tell if the movable modal WDEF is available? I can't see
  1160. >any Gestalt calls that will help... Thanks in advance for any ideas.
  1161.  
  1162. I don't know of any way to check for the moveable-modal capability other
  1163. than checking for System version >= 7.0.  I know that Apple says that this is
  1164. a Bad Thing to do, but I think here it's probably pretty safe.  I mean, how
  1165. likely is it that a future version will _omit_ the moveable-modal window
  1166. variation??
  1167.  
  1168. One more suggestion: if the moveable-modal is unavailable, fall back to
  1169. noGrowDocProc, not dboxProc -- it looks much more like the moveable-modal.
  1170.  
  1171. - -- 
  1172. John Cavallino                  |  EMail: jcav@midway.uchicago.edu
  1173. University of Chicago Hospitals |         John_Cavallino@uchfm.bsd.uchicago.edu
  1174. Office of Facilities Management | USMail: 5841 S. Maryland Ave, MC 0953
  1175. B0 f++ c+ g++ k s++ e+ h- pv    |         Chicago, IL  60637
  1176.  
  1177. +++++++++++++++++++++++++++
  1178.  
  1179. From: haynes@mace.cc.purdue.edu (Carl W. Haynes III)
  1180. Date: 23 Sep 92 22:09:30 GMT
  1181. Organization: Purdue University
  1182.  
  1183. In article <1992Sep23.182634.7236@midway.uchicago.edu> jcav@midway.uchicago.edu writes:
  1184. >
  1185. >One more suggestion: if the moveable-modal is unavailable, fall back to
  1186. >noGrowDocProc, not dboxProc -- it looks much more like the moveable-modal.
  1187.  
  1188. I also go ahead and draw a black rectangle a couple pixels in
  1189. to make it look even more like the movable modal. Only the experts
  1190. can tell the difference :=>
  1191.  
  1192. There aughta be a gestalt selector for this, dontcha think.
  1193.  
  1194. - --
  1195. Carl W. Haynes III  
  1196. Haynes Consulting Services        ||  CWH3@aol.com <-- temp. out of order
  1197. PO Box 2715                       ||  haynes@mace.cc.purdue.edu
  1198. W. Lafayette, IN 47906            ||  hcs@applelink.apple.com
  1199.  
  1200. +++++++++++++++++++++++++++
  1201.  
  1202. From: gurgle@netcom.com (Pete Gontier)
  1203. Date: 24 Sep 92 04:01:49 GMT
  1204. Organization: cellular
  1205.  
  1206. haynes@mace.cc.purdue.edu (Carl W. Haynes III) writes:
  1207.  
  1208. >In article <1992Sep23.182634.7236@midway.uchicago.edu> jcav@midway.uchicago.edu writes:
  1209. >>
  1210. >>One more suggestion: if the moveable-modal is unavailable, fall back to
  1211. >>noGrowDocProc, not dboxProc -- it looks much more like the moveable-modal.
  1212.  
  1213. >I also go ahead and draw a black rectangle a couple pixels in
  1214. >to make it look even more like the movable modal. Only the experts
  1215. >can tell the difference :=>
  1216.  
  1217. Overkill. Just go ahead and use 5 for the variation code, under both
  1218. System 6 and System 7. The system will substitute a normal modal under
  1219. 6. I gone and done it. I don't think it as any accident on Apple's part.
  1220.  
  1221. >There aughta be a gestalt selector for this, dontcha think.
  1222.  
  1223. Yup.
  1224. - -- 
  1225.  Pete Gontier // EC Technology // gurgle@netcom.com
  1226.  
  1227. +++++++++++++++++++++++++++
  1228.  
  1229. From: rson@rhi.hi.is (Mimir Reynisson)
  1230. Date: 24 Sep 92 08:53:46 GMT
  1231.  
  1232. What about using GetResource? WDEF's are resources after all.
  1233. Just keep your Sys 6 WDEF ID different from that of Sys 7, and
  1234. if you cant load the Sys 7 WDEF with GetResource then open your
  1235. windows using the Sys 6 WDEF ID.
  1236.  
  1237. This should be a lot better method than checking if you have system 7,
  1238. for after all some people have ResEdit.
  1239.  
  1240. +++++++++++++++++++++++++++
  1241.  
  1242. From: sw@network-analysis-ltd.co.uk (Sak Wathanasin)
  1243. Date: 24 Sep 92 12:22:06 GMT
  1244. Organization: Network Analysis Ltd
  1245.  
  1246.  
  1247. In article <6!9nbhl.gurgle@netcom.com> (comp.sys.mac.programmer), gurgle@netcom.com (Pete Gontier) writes:
  1248.  
  1249. > Overkill. Just go ahead and use 5 for the variation code, under both
  1250. > System 6 and System 7. The system will substitute a normal modal under
  1251. > 6. I gone and done it. I don't think it as any accident on Apple's part.
  1252.  
  1253. I've just tried this, and it works fine. Many thanks to everyone who responded.
  1254.  
  1255. Sak Wathanasin
  1256. Network Analysis Limited
  1257. 178 Wainbody Ave South, Coventry CV3 6BX, UK
  1258.  
  1259. uucp:      ...!uknet!nan!sw  Phone: (+44) 203 419996
  1260. AppleLink: NAN.LTD           Internet: sw@network-analysis-ltd.co.uk
  1261.  
  1262. +++++++++++++++++++++++++++
  1263.  
  1264. From: de19@umail.umd.edu (Dana S Emery)
  1265. Date: 27 Sep 92 12:40:44 GMT
  1266. Organization: Personal
  1267.  
  1268. In article <6!9nbhl.gurgle@netcom.com>, gurgle@netcom.com (Pete Gontier)
  1269. wrote:
  1270. > haynes@mace.cc.purdue.edu (Carl W. Haynes III) writes:
  1271. > >In article <1992Sep23.182634.7236@midway.uchicago.edu> jcav@midway.uchicago.edu writes:
  1272. > >>
  1273. > >>One more suggestion: if the moveable-modal is unavailable, fall back to
  1274. > >>noGrowDocProc, not dboxProc -- it looks much more like the moveable-modal.
  1275. > >I also go ahead and draw a black rectangle a couple pixels in
  1276. > >to make it look even more like the movable modal. Only the experts
  1277. > >can tell the difference :=>
  1278. > Overkill. Just go ahead and use 5 for the variation code, under both
  1279. > System 6 and System 7. The system will substitute a normal modal under
  1280. > 6. I gone and done it. I don't think it as any accident on Apple's part.
  1281.  
  1282.  
  1283. Overkill???  users want to be able to move the damn thing out of the way so
  1284. that they can see what is going on behind it, and this is so cheap to do as
  1285. pales beside the alternative of getting a bad review or even answering the
  1286. odd letter/phone complaint.  
  1287.  
  1288. Provide your own as a fallback to the officious version, and tell any user
  1289. who ResEdit's your fallback out from under you to put it back by golly.
  1290.  
  1291.  
  1292. > >There aughta be a gestalt selector for this, dontcha think.
  1293. > Yup.
  1294. > -- 
  1295. >  Pete Gontier // EC Technology // gurgle@netcom.com
  1296.  
  1297. Ayup
  1298.  
  1299. - --
  1300.  
  1301. Dana S Emery <de19@umail.umd.edu> | "Novo, de Novo,
  1302.                                   |     de novo, de no-o-o-o-o---, 
  1303.                                   | Novemba come an' dey gonna go home."
  1304.  
  1305. +++++++++++++++++++++++++++
  1306.  
  1307. From: lari@strauss.cs.unc.edu (Humayun Lari)
  1308. Date: 29 Sep 92 00:25:58 GMT
  1309. Organization: The University of North Carolina at Chapel Hill
  1310.  
  1311. > haynes@mace.cc.purdue.edu (Carl W. Haynes III) writes:
  1312. [regarding using a regular noGrowDocProc if the movable-modal dialog isn't
  1313. around]
  1314. >I also go ahead and draw a black rectangle a couple pixels in
  1315. >to make it look even more like the movable modal. Only the experts
  1316. >can tell the difference :=>
  1317.  
  1318. Uh-oh. As all of the "eleven developers" (to quote Tog) who've read the human
  1319. interface note on movable-modal dialogs will attest, trying to make a regular
  1320. window look like a movable modal is a Bad Thing (tm). People are already
  1321. confused enough. :-)
  1322.  
  1323. 'Course, we also have those wonderful DOS-escapees who implement movable-modal
  1324. dialogs that can't be moved... <sigh>
  1325.  
  1326. Humayun Lari
  1327. (lari@cs.unc.edu)
  1328.  
  1329. ---------------------------
  1330.  
  1331. End of C.S.M.P. Digest
  1332. **********************
  1333.